package com.coolbi.security.dao.impl;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;

import com.coolbi.security.dao.UserDao;
import com.coolbi.security.entity.User;
import com.coolbi.security.mapper.UserMapper;

public class UserDaoImpl implements UserDao {
	
	@Autowired
	private UserMapper userMapper;
	public void setUserMapper(UserMapper userMapper) {
		this.userMapper = userMapper;
	}

	@Override
	public List<User> find(Map<String, Object> parameter) {
		return userMapper.listByParameter(parameter);
	}

	@Override
	public List<User> find(Map<String, Object> parameter, int offset, int limit) {
		parameter.put("offset", offset);
		parameter.put("limit", limit);
		return userMapper.listByParameterPage(parameter);
	}

	@Override
	public int count(Map<String, Object> parameter) {
		return userMapper.countByParameter(parameter);
	}

	@Override
	public List<User> search(String keyword, int offset, int limit) {
		Map<String, Object> parameter=new HashMap<String, Object>();
		parameter.put("keyword", keyword);
		parameter.put("offset", offset);
		parameter.put("limit", limit);
		return userMapper.search(parameter);
	}

	@Override
	public int countByKeyword(String keyword) {
		Map<String, Object> parameter=new HashMap<String, Object>();
		parameter.put("keyword", keyword);
		return userMapper.countByKeyword(parameter);
	}

	@Override
	public User save(User obj) {
		userMapper.save(obj);
		return obj;
	}

	@Override
	public int update(User obj) {
		return userMapper.update(obj);
	}

	@Override
	public int delete(long id) {
		return userMapper.delete(id);
	}

	@Override
	public User get(long id) {
		return userMapper.get(id);
	}

	@Override
	public List<User> list() {
		return userMapper.list();
	}

	@Override
	public List<User> list(int offset, int limit) {
		Map<String, Object> parameter=new HashMap<String, Object>();
		parameter.put("offset", offset);
		parameter.put("limit", limit);
		return userMapper.listByPage(parameter);
	}

	@Override
	public int count() {
		return userMapper.count();
	}

	@Override
	public int countByTel(String tel) {
		return userMapper.countByTel(tel);
	}

	@Override
	public int countByEmail(String email) {
		return userMapper.countByEmail(email);
	}

	@Override
	public int countByUserName(String username) {
		return userMapper.countByUserName(username);
	}

	/**根据ID修改管理员密码*/
	@Override
	public int updatePassword(String password, long id) {
		Map<String, Object> parameter = new HashMap<String, Object>();
		parameter.put("id", id);
		parameter.put("password", password);
		return userMapper.updatePassword(parameter);
	}

	@Override
	public int lockedUser(long id, boolean isLock) {
		Map<String, Object> parameter = new HashMap<String, Object>();
		parameter.put("id", id);
		parameter.put("isLock", isLock);
		return userMapper.lockedUser(parameter);
	}

	@Override
	public User findUserByUsername(String username) {
		return userMapper.findUserByUsername(username);
	}

	@Override
	public List<User> findAllUserNames() {
		return userMapper.findAllUserNames();
	}
}
